﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DearlerPlatfrom.Core.Repository
{
    public static class LinqExtensiions
    {
        public async static IAsyncEnumerable<TEntity> WhereAsync<TEntity>(this DbSet<TEntity> dbset, Func<TEntity, bool> predicate)
            where TEntity : class
        {
            var res = dbset.Where(predicate);
            foreach (var item in res)
            {
                yield return item;
            }
        }

        public async static Task<List<TEntity>> ToListAsync<TEntity>(this IAsyncEnumerable<TEntity> listAsync)
        {
            List<TEntity> entities = new();
            await foreach (var item in listAsync)
            {
                entities.Add(item);
            }
            return entities;
        }
    }
}
